(require* sketch/parse/rule/common/line)
(require* sketch/parse/rule/common/block)
(require* sketch/parse/rule/common/arrow)
(require* sketch/parse/rule/common/arrowx)

(import sketch.shape.domain.uml.*)

(defrule uml-interface
    ""
    ?fr <- (shape (name "Rectangle") (obj ?r))
    ?fl <- (shape (name "Line") (obj ?l))
    (test (call ShapePredicate horizontalLine ?l))
    (test (> (?l length) (* 0.5 (?r getWidth))))
	(test (call ShapePredicate containsRectangleLine ?r ?l))
    =>
    (printout "recognize uml-interface = rectangle, line")
    (bind ?sh (new UMLInterface))
    (?sh setRefPoint (?r getRefPoint))
    (?sh setWidth (?r getWidth))
    (?sh setHeight (?r getHeight))
    (retract ?fr)
    (retract ?fl)
    (assert (shape
            (name "UMLInterface")
            (obj ?sh)
            (children ?r ?l)))
    (recognize ?sh (list-children (create$ ?r ?l))))

(defrule uml-class
    ""
    ?fi <- (shape (name "UMLInterface") (obj ?i))
    ?fl <- (shape (name "Line") (obj ?l))
    (test (call ShapePredicate horizontalLine ?l))
    (test (> (?l length) (* 0.5 (?i getWidth))))
	(test (call ShapePredicate containsRectangleLine ?i ?l))
    =>
    (printout "recognize uml-class = uml-interface, line")
    (bind ?sh (new UMLClass))
    (?sh setRefPoint (?i getRefPoint))
    (?sh setWidth (?i getWidth))
    (?sh setHeight (?i getHeight))
    (retract ?fi)
    (retract ?fl)
    (assert (shape
            (name "UMLClass")
            (obj ?sh)
            (children ?i ?l)))
    (recognize ?sh (list-children (create$ ?i ?l))))


